package logic

import (
	"context"
	"sport/models/mysql"

	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentListLogic {
	return &CommentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论列表
func (l *CommentListLogic) CommentList(in *sportrpc.CommentListRequest) (*sportrpc.CommentListResponse, error) {
	// todo: add your logic here and delete this line
	var post []mysql.Comment
	mysql.DB.Find(&post)
	var posts []*sportrpc.Commentlist
	for _, m := range post {
		list := sportrpc.Commentlist{
			UserId:  int64(m.UserId),
			PostId:  int64(m.PostId),
			Content: m.Content,
		}
		posts = append(posts, &list)
	}
	return &sportrpc.CommentListResponse{
		List: posts,
	}, nil
}
